import { Link } from "react-router-dom"
import { memo } from "react"


const ButtonInfo = memo((props) => {
    const { isCurrentUser, profile, follow, unfollow } = props
    //处理:关注 和 取消 关注
    const handleClick = ev => {
        ev.preventDefault()
        if (profile.following) {
            unfollow(profile.username)
        } else {
            follow(profile.username)
        }
    }

    if (isCurrentUser) {//a和a
        return (<Link
            to="/setting"
            className="btn btn-sm btn-outline-secondary action-btn"
        >
            <i className="fa fa-cog"></i>编辑设置
        </Link>)
    } else {   //a 和 b
        return (
            <button
                //   className="btn btn-sm  action-btn"
                className={profile.following ? 'btn-secondary' : 'btn-outline-secondary'}
                onClick={handleClick}
            >
                <i className="fa fa-user-plus"></i> {' '}
                {profile.following ? "取消关注" : "添加关注"}
            </button>
        )
    }
})

export default ButtonInfo